<template>
    <!-- 廉洁共建活动 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button v-btnPermission="'di_007_add_01'" class="mb12" icon="plus" type="primary" @click="handleManage(2)">新增</a-button>
            <!-- 表格 -->
            <list-table
                    ref="table"
                    tableLayout="fixed"
                    size="default"
                    rowKey="id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    showPagination="auto"
            >
                <template slot="enabled" slot-scope="text, record">
                    {{record.levelName}}
                </template>
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <span v-btnPermission="'di_007_loo_04'" >
                        <a @click="handleManage(0, record)">查看</a>
                    </span>
                    <span v-btnPermission="'di_007_edi_02'" >
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <span v-btnPermission="'di_007_del_03'" >
                        <a class="del_btn" @click="handleRemove(record)">删除</a>
                    </span>
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
  import { STable } from '@/components' // 表格
  import { getList, remove } from '@/api/disciplineInspection/culturalEducation/ljAction' // api
  import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject.vue'
  import Selector from '@/components/Select/Selector'
  import BasePage from '@/views/basePage' // 基础配置

  const levelArr= [
    {
      value: 'PD',
      label: '项目部'
    },
    {
      value: 'BC',
      label: '分公司'
    },
    {
      value: 'CO',
      label: '公司'
    },
  ];
  const searchArr = [
    // 搜索框
    {
      name: '活动名称',
      type: 'input',
      value: 'title',
    },
    {
      name: '层级',
      value: 'levelId',
      type: 'select',
      data: levelArr
    },
    // {
    //   name: '层级',
    //   type: Selector,
    //   valueKey: 'levelId',
    //   selectType: '1',
    //   urlType: 'union',
    // },
    {
      name: '单位',
      type: 'input',
      value: 'unitName',
    },
    {
      name: '负责人',
      type: 'input',
      value: 'chargeName',
    },
    {
      name: '日期',
      type: 'dateRange',
      value: 'meetTimeRange',
      attr: {
        rangeFormat: ['startTime', 'endTime'],
      },
    },
  ]
  const columns = [
    {
      title: '序号',
      width: 80,
      dataIndex: 'index',
      customRender() {
        return arguments[2] + 1
      },
    },
    {
      title: '活动名称',
      ellipsis: true,
      dataIndex: 'title',
    },
    {
      title: '层级',
      dataIndex: 'levelName',
      ellipsis: true,
      scopedSlots: {
        customRender: 'enabled'
      },
    },
    {
      title: '单位',
      ellipsis: true,
      dataIndex: 'unitName',
    },
    {
      title: '日期',
      ellipsis: true,
      dataIndex: 'meetTime',
    },
    {
      title: '地址',
      ellipsis: true,
      dataIndex: 'address',
    },
    {
      title: '负责人',
      ellipsis: true,
      dataIndex: 'chargeName',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '180px',
      align: 'center',
      scopedSlots: { customRender: 'action' },
    },
  ]
  export default {
    name:'a'+ Date.now(),
    extends: new BasePage(),
    components: {
      STable,
      SelectCompanyAndProject,
    },
    data() {
      this.columns = columns
      this.searchArr = searchArr
      return {
        queryParam: {}, // 查询参数
        loadData: (parameter) => {
          const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
          return getList(requestParameters).then((res) => {
            return res
          })
        },// 加载数据方法 必须为 Promise 对象
        removeApi: { remove: remove }, // api
        editModel: 0,
        form: {},
      }
    },
    methods: {
      // 搜索
      search(value) {
        value && (this.queryParam = value)
        this.$refs.table.refresh(true)
      },
      // 删除
      handleRemove(e){
        const that = this;
        this.$confirm({
          title: '温馨提示',
          content: `确认移除？`,
          onOk: () => {
            return remove(e.id).then(() => {
              this.$message.success('移除成功！')
              // that.search()
              // that.closeForm();
              that.$refs.table.refresh(true) })
          },
        })
      },
      // 操作栏
      handleManage(type, record) {
        this.editModel = type
        let query = {
          editModel: type,
        }
        if (record && record.id) {
          query.id = record.id
        }
        this.$router.push({
          path: '/discipline/culturalEducation/action/add',
          query,
        })
      },
    },
  }
</script>
